<?php
namespace Admin\Controller;
use Think\Controller;
use Think\Page;

use Common\Controller\BaseController;
class RuleController extends BaseController{
    public function add(){
        $this->assign('url',U('Rule/insert'));
        $this->assign('title','权限添加');
        $this->assign('info','添加');
        $this->display('Rule_info');
    }
    
    
    
    public function insert(){
        if (D('Rule')->addRule()){
            $this->success('添加成功！',U('Rule/View'));
        }else {
            $this->error('添加失败！');
        }
    }
    
    public function edit(){
        $this->assign('title','权限更新');
        $this->assign('url',U('Rule/update'));
        $this->assign('Ruleinfo',D('Rule')->RuleInfo());
        $this->assign('info','更新');
        $this->display('Rule_info');
    }
    public function update(){
        $result=D('Rule')->updateInfo();
        if (false !== $result || 0 !== $result){
            $this->success('更新成功！',U('Rule/view'));
        }else {
            $this->error('更新失败！');
        }
    }
    
    public function delete(){
        if(D('Rule')->delInfo()){
            $data['state']=1;
            $data['msg']='删除成功';
            $this->ajaxReturn($data);
        }else {
            $data['state']=0;
            $data['msg']='删除失败';
            $this->ajaxReturn($data);
        }
    }
    
  
      
    public function View(){
        $this->assign('title','权限列表');
        $this->assign('info','添加');
        $count=D('Auth_rule')->count();
        $page=new Page($count, 13);
        $page->setConfig('first', '首页');
        $page->setConfig('prev', '上一页');
        $page->setConfig('next', '下一页');
        $page->setConfig('last', '末页');
        $page->rollPage='8';
        $page->setConfig('theme', '%HEADER%  共    %TOTAL_PAGE% 页   %FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%');
        $show=$page->show();
        $this->assign('rulelist',D('Auth_rule')->limit($page->firstRow.','.$page->listRows)->order('convert(title using utf8) asc')->select());
        $this->assign('page',$show);
        $this->display('Rule_list');
    }
    
}